//
//  CommunityNoticeService.m
//  homeland
//
//  Created by zmingchun on 14-7-28.
//  Copyright (c) 2014年 xzysun. All rights reserved.
//  社情公告服务类
//

#import "CommunityNoticeService.h"
#import "UIImageView+WebCache.h"
#import "NoticesItem.h"
#import "DataStoreService.h"
#import "CommunityNoticeCell.h"

@implementation CommunityNoticeService
//请求参数集
NSMutableDictionary *params;

- (void)loadDataWithKey:(NSString *)keyOrNil{
    _currentPageNo = 1;
    if (self.dataList) {
        self.dataList = nil;
    }
    // 社情公告
    _dataItemName = @"NoticesItem";
    NSDictionary *_config = [super paramDic];
    
    params = [NSMutableDictionary dictionary];
    [params setValue:@"3" forKey:@"isFromInterface"];//社区通知公告；3
    [params setValue:[_config objectForKey:@"streetId"] forKey:@"streetId"];
    [params setValue:[_config objectForKey:@"communityId"] forKey:@"communityId"];
    [params setValue:[_config objectForKey:@"partyMember"] forKey:@"partyMember"];
    if (keyOrNil) {
        [params setValue:keyOrNil forKey:@"title"];
    } else {
        [params setValue:@"" forKey:@"title"];
    }
    [self doHttpPost:SERVER_URL_COMMUNITY_NOTICE_LIST headers:nil path:[NSString stringWithFormat:@"/%d",_currentPageNo] parameters:params];
}

- (void)loadMoreDataWithKey:(NSString *)keyOrNil{
    if (!params || [params count]==0) {
        params = [NSMutableDictionary dictionary];
    }
    if (keyOrNil) {
        [params setValue:keyOrNil forKey:@"title"];
    } else {
        [params setValue:@"" forKey:@"title"];
    }
    // 社情公告
    _dataItemName = @"NoticesItem";
    [self doHttpPost:SERVER_URL_COMMUNITY_NOTICE_LIST headers:nil path:[NSString stringWithFormat:@"/%d",_currentPageNo + 1] parameters:params];
}

- (CGFloat)heightForCellAtRow:(NSIndexPath *)index{
    return 60.0f;//每行64
}

/**展示数据*/
- (void)configCell:(UITableViewCell *)cell atIndex:(NSIndexPath *)index{
    if (self.dataList == nil || self.dataList.count == 0) {
        return;
    }
    // 社情公告
    NoticesItem *item = [self.dataList objectAtIndex:index.row];
    CommunityNoticeCell *tempCell = (CommunityNoticeCell *)cell;
    tempCell.titleLabel.text = [CommonUtil dealNullObject:item.title];
    tempCell.timeLabel.text = [CommonUtil formatDateStr:item.submitDate style:@"yyyy-MM-dd"];
    tempCell.typeLabel.text = [[@"【" stringByAppendingString:[CommonUtil dealNullObject:item.type]] stringByAppendingString:@"】"];
}

@end
